class Solution {
    public int maxProfit(int[] prices) {
        if(prices.length == 0) {
            return 0;
        }
        int min = prices[0];
        int max = 0;
        for(int i = 0;i < prices.length;i++) {
            min = Math.min(min,prices[i]);
            int cha = prices[i] - min;
            max = Math.max(cha,max);
        }
        return max;
    }
}